import { isInArray } from "@/utils"

export default class ManageMissonExtension extends Room {
    /* 近塔填充 */
    public Task_NTower():void{
        if (Game.time % 17) return
        if (!this.memory.StructureIdData.storageID || !this.memory.StructureIdData.NtowerID) return
        var NTower = Game.getObjectById(this.memory.StructureIdData.NtowerID as string) as StructureTower
        var storage_ = global.Stru[this.name]['storage'] as StructureStorage
        if (!NTower || !storage_)
        {
            delete this.memory.StructureIdData.storageID
            delete this.memory.StructureIdData.NtowerID
            return
        }
        if (storage_.store['energy'] < 1000) return
        /* 如果NTower的能量储备低于600就触发近塔填充任务 */
        if (NTower.store.getUsedCapacity(RESOURCE_ENERGY) < 500 && this.RoleMissonNum('manage','物流运输') < 1)
        {
            var thisTask = this.Public_Carry({'manage':{num:1,bind:[]}},20,this.name,storage_.pos.x,storage_.pos.y,this.name,NTower.pos.x,NTower.pos.y,'energy',500)
            this.AddMisson(thisTask)   
        }
    }

    /* 链接送仓 */
    public Task_Clink():void{
        if (Game.time % 15) return
        if (!this.memory.StructureIdData.center_link) return
        var center_link = Game.getObjectById(this.memory.StructureIdData.center_link as string) as StructureLink
        if (!center_link) {delete this.memory.StructureIdData.center_link;return}
        var storage_ =  global.Stru[this.name]['storage'] as StructureStorage
        if (!storage_) {return}
        if (storage_.store.getFreeCapacity() <= 10000) return   // storage满了就不挂载任务了
        for (var i of this.memory.Misson['Structure'])
        {
            if (i.name == '链传送能' && isInArray(i.structure,this.memory.StructureIdData.center_link))
            return
        }
        if (center_link.store.getUsedCapacity('energy') >= 400 && this.RoleMissonNum('manage','物流运输') < 1)
        {
            var thisTask = this.Public_Carry({'manage':{num:1,bind:[]}},20,this.name,center_link.pos.x,center_link.pos.y,this.name,storage_.pos.x,storage_.pos.y,'energy')
            this.AddMisson(thisTask)   
        }
    }

    /* 工厂加工 */
    public Task_Factory(misson:MissionModel):void{
        var factory_ = global.Stru[this.name]['factory']
        if (!factory_){console.log(this.name,"未发现工厂！")}
        
    }
    

}